#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=100010,maxm=210,maxt=1e4+10;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL tree[maxn*2][130],pt=0,flag[maxn*2*26],fail[maxn*2*26];
LL total=0;
char str[maxm],p[maxt];
inline void ins(const char* s,LL id){
    LL n=strlen(s);LL cur=0;
    for(int i=0;i<n;i++){
        LL c=s[i];
        if(!tree[cur][c]) tree[cur][c]=++pt;
        cur=tree[cur][c];
    }
    flag[cur]=id;
}
inline void getfail(){
    queue<LL>que;
    fail[0]=0;
    for(int c=0;c<130;c++){
        LL u=tree[0][c];
        if(u){
            fail[u]=0;que.push(u);
        }
    }
    while(!que.empty()){
        LL r=que.front();que.pop();
        for(int c=0;c<130;c++){
            LL u=tree[r][c];
            if(!u) continue;
            que.push(u);
            LL v=fail[r];
            while(v&&!tree[v][c]) v=fail[v];
            fail[u]=tree[v][c];
        }
    }
}
inline void fd(const char* s,const LL id){
    vector<int>ans;
    LL n=strlen(s);
    LL j=0;
    for(int i=0;i<n;i++){
        if(ans.size()>3) break;
        LL c=s[i];
        while(j&&!tree[j][c]) j=fail[j];
        j=tree[j][c];
        LL temp=j;
        while(temp!=0){
            if(ans.size()>3) break;
            if(flag[temp]) ans.push_back(flag[temp]);
            temp=fail[temp];
        }
    }
    if(ans.size()){
        ++total;
        cout<<"web "<<id<<":";
        sort(ans.begin(),ans.end());
        for(int i=0;i<ans.size();i++){
            cout<<" "<<ans[i];
        }cout<<endl;
    }
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>str;
        ins(str,i);
    }
    getfail();
    LL m;cin>>m;
    for(int i=1;i<=m;i++){
        cin>>p;
        fd(p,i);
    }
    cout<<"total: "<<total<<endl;
   	return 0;
}

